In this article, I will show you how to use animate in jQuery for “like” button. Create a css class with background image, size, transition and animation effects, etc. for implementing twitter’s social like button using css3 library.
When the user clicks the like button heart it will be bursting for the period of time continuously. The image background position changes from left to right using jQuery button animation effects.
Step 1: Create a css class file and named as heart.css. Copy and paste the following code.
.heart {
cursor: pointer;
height: 50px;
width: 50px;
background-image: url( 'http://www.infinetsoft.com/Uploads/20161111063754heartanimation.png');
background-position: left;
background-repeat: no-repeat;
background-size: 2900%;
}
.heart:hover {
background-position: right;
}
.animating {
animation: heart-burst .800s steps(28) 2;
}
@keyframes heart-burst {
from {
background-position: left;
}
to {
background-position: right;
}
}
Step 2: Copy and paste the following code.
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function () {
$(".heart").on('click touchstart', function () {
$(this).toggleClass('animating');
});
$(".heart").on('animationend', function () {
$(this).toggleClass('animating');
});
});
</script>
<div class="heart"> </div>
jQuery animate examples:
Post your comments / questions
Recent Article
- FieldError: Cannot resolve keyword 'id' into field in Django project
- How to hide the ID field from the Django admin?
- It is impossible to add a non nullable field without specifying a default. Django error
- ImportError: cannot import name 'url' from 'django.conf.urls' - Django Error
- How to Enable Virtualization in BIOS Security Settings in Intel Processors For Android Studio?
- Dependency 'androidx.activity:activity:1.8.0' requires libraries and applications that depend on it.
- AttributeError: 'NoneType' object has no attribute 'get_text' - Python
- ModuleNotFoundError: No module named 'openpyxl' - Python
Related Article